package com.winning.core.job;

import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.StatefulJob;
import org.springframework.stereotype.Service;

public abstract class BaseJob implements StatefulJob {
    //接口任务正在运行
    protected static final String JOB_IS_RUNNING = "1";

    //接口任务停止
    protected static final String JOB_WAS_STOPED = "-1";

    public final static String XML_TEMP_CONFIG_BEAN = "XMLTempConfigBean";

    //PlatBasicDataDaoInter
    public final static String PLAT_BASIC_DATA_SERVICE = "PlatBasicDataService";

    //任务间共享数据的KEY
    public final static String DATA_INTERFACE_PARAM = "dataInterfaceParam";

    //子任务下标key
    public final static String CHILD_JOB_INDEX_KEY = "childJobIndexKey";

    //子任务总数key
    public final static String CHILD_JOB_NUMBER_KEY = "childJobNumberKey";

    //每一个线程执行的数据量
    public static final int PER_BATCH_THREAD_NUMBER = 1000;

    public static final String COLUMN_COUNT = "TOTALCOUNT";

    @Override
    public abstract void execute(JobExecutionContext context) throws JobExecutionException;


    /**
     * @param @param  context
     * @param @return
     * @return String
     * @throws
     * @Title: getJobName
     * @Description: 获取任务名称
     */
    protected String getJobName(JobExecutionContext context) {
        JobDetail jobDetail = context.getJobDetail();

        //任务唯一名称，从共享数据MAP中得到唯一的数据
        String jobInstanceName = jobDetail.getName();
        return jobInstanceName;
    }

    /**
     * @param @param  context
     * @param @return
     * @return JobDataMap
     * @throws
     * @Title: getJobDataMap
     * @Description: JobDetail之间共享的数据Map对象
     */
    protected JobDataMap getJobDataMap(JobExecutionContext context) {
        JobDetail jobDetail = context.getJobDetail();

        JobDataMap jobDataMap = jobDetail.getJobDataMap();

        return jobDataMap;
    }


}
